package com.hcinfos.gsoo.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hcinfos.gsoo.R;
import com.hcinfos.gsoo.config.Urls;
import com.hcinfos.gsoo.enity.City;
import com.hcinfos.gsoo.enity.Gift;
import com.hcinfos.gsoo.enity.ShopInfo;
import com.lidroid.xutils.BitmapUtils;

public class GiftAdapter extends BaseAdapter {

	private List<Gift> list;
	private LayoutInflater mInflater;
	public int index = 0;
	private BitmapUtils bitmapUtils;

	public GiftAdapter(Context context, List<Gift> list) {
		this.list = list;
		mInflater = LayoutInflater.from(context);
		bitmapUtils = new BitmapUtils(context);
		bitmapUtils.configDefaultLoadingImage(R.drawable.tc_shop_default_logo);// 默认背景图片
		bitmapUtils
				.configDefaultLoadFailedImage(R.drawable.tc_shop_default_logo);// 加载失败图片
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TypeHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.gift_child, null);
			holder = new TypeHolder();
			holder.icon_iv = (ImageView) convertView.findViewById(R.id.icon_iv);
			holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
			holder.price_tv = (TextView) convertView
					.findViewById(R.id.price_tv);
			holder.des_tv = (TextView) convertView.findViewById(R.id.des_tv);
			holder.price_tv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
			holder.inter_tv = (TextView) convertView
					.findViewById(R.id.inter_tv);
			convertView.setTag(holder);
		} else {
			holder = (TypeHolder) convertView.getTag();
		}
		Gift gift = list.get(position);
		holder.name_tv.setText(gift.getGiftName() + "  ["
				+ gift.getSupplierName() + "]");
		holder.price_tv.setText("￥ " + gift.getPrice());
		String des = gift.getAttention();
		holder.des_tv.setText(des);
		bitmapUtils.display(holder.icon_iv, Urls.url + "/" + gift.getImgUrl());
		holder.inter_tv.setText("积分：" + gift.getIntegrate());
		return convertView;
	}

	private final class TypeHolder {
		ImageView icon_iv;
		TextView name_tv;
		TextView price_tv;
		TextView des_tv;
		TextView inter_tv;

	}

	public void setDataChange(List<Gift> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
